package configuration;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;

public class PropertyUtils {
	private static Properties prop = new Properties();

	public static Set<String> getPropertyConsole() {
        final Set<String> properties = new HashSet<String>();
        for(Object objKey:prop.keySet()){
            final String key = (String) objKey;
            if( Pattern.compile("console.\\d{1,}").matcher(key).find()){
                properties.add(prop.getProperty(key));
            }
        }
        return properties;
	}


    public static Map<String,String> getProperties(String filter){
        final Map<String,String> properties = new HashMap<String,String>();
        for(Object objKey:prop.keySet()){
            final String key = (String) objKey;
            if(key.toLowerCase().contains("." + filter.toLowerCase() + ".")){
                properties.put(key,prop.getProperty(key));
            }
        }
        return properties;
    }
    public static String getProperty(String key) {
        return prop.getProperty(key);
    }


    static {

		try {
			// load a properties file
            final InputStream inputStream=Thread.currentThread().getContextClassLoader().getResourceAsStream("configuration.properties");
			prop.load(inputStream);

		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
}
